package com.frame.flux.ui;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.Toast;

import com.data.entity.Image;
import com.frame.flux.base.BaseFluxFragment;
import com.frame.flux.store.BaseStore;
import com.ui.main.R;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;

/**
 * @Description
 * @Author luxiao418
 * @Email luxiao418@pingan.com.cn
 * @Date 16/8/12 16:04
 * @Version v2.6.0
 */
public class FluxFragment extends BaseFluxFragment implements SimpleRecyclerCardAdapter.OnItemActionListener {
    @Bind(R.id.recyclerview)
    RecyclerView mRecyclerview;
    private SimpleRecyclerCardAdapter mSimpleRecyclerAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_flux;
    }

    @Override
    protected BaseStore getStore() {
        return null;
    }

    @Override
    protected void afterCreate(Bundle savedInstanceState) {
//        if (null != savedInstanceState) {
//            mNewsListStore = (MainListStore) savedInstanceState.getSerializable(BundleKey.NEWS_LIST_STORE);
//        } else if (mNewsListStore == null) {
//            mNewsListStore = new NewsListStore();
//        }
    }

    @Override
    protected void initView() {
        Image mImage = new Image();
        Map<String, String> map = new HashMap<>();
        map.put("type", "电子");
        mImage.setParam(map);
        mImage.getPageAt(0).subscribe(imageData -> {
                    mSimpleRecyclerAdapter = new SimpleRecyclerCardAdapter(mActivity, imageData.results);
                    mRecyclerview.setAdapter(mSimpleRecyclerAdapter);
                    //设置网格布局管理器
                    mRecyclerview.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
                    mSimpleRecyclerAdapter.setOnItemActionListener(this);
                }
        );
    }

    @Override
    public void onItemClickListener(View v, int pos) {
        Toast.makeText(mActivity, "-单击-" + pos, Toast.LENGTH_SHORT).show();
    }

    @Override
    public boolean onItemLongClickListener(View v, int pos) {
        Toast.makeText(mActivity, "-长按-" + pos, Toast.LENGTH_SHORT).show();
        return false;
    }
}
